<?php 
require ("webfunc.php");
$qstr = $_SERVER['REQUEST_URI'];
$qstr = substr($qstr, 17 + strpos($qstr, $_SERVER['SCRIPT_NAME']));
$TAPIurl = "https://qqfarn.appspot.com/twiauth/API".$qstr;
$proxyurl = "https://qqfarn.appspot.com/twiauth";
$islog = "false";
if($islog == "true")
{
	$filename = "test.log";
	if(!$handle = fopen($filename, "a+"))
	{
		echo("open error:".$filename);
	}
}
if($_SERVER['REQUEST_METHOD'] == "GET")
{
	$data = vget($TAPIurl);
	if($data == NULL)
	{
		$data = vget($TAPIurl);
	}
	if($islog == "true")
	{
		if(!fwrite($handle,   $qstr."\n"))
		{
			echo("write error:".$filename);
		} 
		if(!fwrite($handle,   $_SERVER['HTTP_USER_AGENT']."\n"))
		{
			echo("write error:".$filename);
		} 
		foreach ($_SERVER as $key => $value)
		{
			fwrite($handle,   $key.":".$value."\n");
		}
		if(!fwrite($handle,   "===========================================\n"))
		{
			echo("write error:".$filename);
		} 
		if(!fwrite($handle,   $data."\n"))   {
			echo("write error:".$filename);
		} 
		if(!fwrite($handle,   "+++++++++++++++++++++++++++++++++++++++++++\n"))
		{
			echo("write error:".$filename);
		} 
	}
	echo($data);
}
if($_SERVER['REQUEST_METHOD'] == "POST")
{
	$proxyurl = $proxyurl.$qstr;
	$postdata = array();
	foreach($_POST as $k => $v){
		$postdata[$k] = $v;
	}
	if(array_key_exists('status',$postdata))
	{
		$postdata['status'] = "/".stripslashes($postdata['status']);
	}
	$data = vpost($proxyurl, $postdata);
	if($data == NULL)
	{
		$data = vpost($proxyurl, $postdata);
	}
	if($islog == "true")
	{
		if(!fwrite($handle,   $qstr."\n"))
		{
			echo("write error:".$filename);
		} 
		if(!fwrite($handle,   $_SERVER['HTTP_USER_AGENT']."\n"))
		{
			echo("write error:".$filename);
		} 
		if(!fwrite($handle,   "===========================================\n"))
		{
			echo("write error:".$filename);
		} 
		if(!fwrite($handle,   $data."\n"))   {
			echo("write error:".$filename);
		} 
		if(!fwrite($handle,   "===========================================\n"))
		{
			echo("write error:".$filename);
		} 
		foreach($postdata as $k => $v){
			if(!fwrite($handle, $k."::"))
			{
				echo("write error:".$filename);
			} 
			if(!fwrite($handle, $v."\n"))
			{
				echo("write error:".$filename);
			}
		}
		if(!fwrite($handle,   "+++++++++++++++++++++++++++++++++++++++++++\n"))
		{
			echo("write error:".$filename);
		}
	}
	echo($data);
}
fclose($handle); 
?>